#include "DominoPlayer.h"
#include "XInputManager.h"


void DominoPlayer::CreateGeometry()
{
	PhysicsBall::CreateGeometry();
}

void DominoPlayer::AddObjectToSimulation( hkpWorld* theWorld )
{
	PhysicsBall::AddObjectToSimulation(theWorld);

	havokRigidBody->setName("PLAYER");
}

void DominoPlayer::Init()
{
	PhysicsBall::Init();

	Score = 0;
}

void DominoPlayer::Update()
{
	if (GamePadManager::Get().GetState(0).LeftStick.Y>0)
	{
		MoveForward(300,D3DXVECTOR3(0.0f,0,10.0f));
	}
	if (GamePadManager::Get().GetState(0).LeftStick.Y<0)
	{
		MoveBackward(300,D3DXVECTOR3(0,0,10.0f));
	}
	if (GamePadManager::Get().GetState(0).LeftStick.X<0)
	{
		MoveLeft(300,D3DXVECTOR3(-10.0f,0,0));
	}
	if (GamePadManager::Get().GetState(0).LeftStick.X>0)
	{
		MoveRight(300,D3DXVECTOR3(-10.0f,0,0));
	}
	if (GamePadManager::Get().GetState(0).Buttons.A)
	{
		Jump(D3DXVECTOR3(0,15.0f,0));
	}
	PhysicsBall::Update();
}

void DominoPlayer::MoveForward(float speed, const D3DXVECTOR3& direction)
{
	hkVector4 impulse(direction.x, direction.y, direction.z);
	havokRigidBody->applyLinearImpulse(impulse);
	havokRigidBody->applyAngularImpulse(impulse);
}

void DominoPlayer::MoveBackward(float speed, const D3DXVECTOR3& direction)
{
	hkVector4 impulse(-direction.x, -direction.y, -direction.z);
	havokRigidBody->applyLinearImpulse(impulse);
	havokRigidBody->applyAngularImpulse(impulse);
}

void DominoPlayer::MoveLeft(float speed, const D3DXVECTOR3& direction)
{
	hkVector4 impulse(direction.x, direction.y, direction.z);
	havokRigidBody->applyLinearImpulse(impulse);
	havokRigidBody->applyAngularImpulse(impulse);
}

void DominoPlayer::MoveRight(float speed, const D3DXVECTOR3& direction)
{
	hkVector4 impulse(-direction.x, -direction.y, -direction.z);
	havokRigidBody->applyLinearImpulse(impulse);
	havokRigidBody->applyAngularImpulse(impulse);
}
void DominoPlayer::Jump(const D3DXVECTOR3& direction)
{
	hkVector4 impulse(direction.x, direction.y, direction.z);
	havokRigidBody->applyLinearImpulse(impulse);
}
